package leetcode;

import java.util.LinkedList;

/**
 * Created by Ghost on 2014/12/25 0025.
 * 484ms
 */
public class Candy {

    public int candy(int[] ratings) {
        int[] rst = new int[ratings.length];
        for(int i=0;i<rst.length;i++)
            rst[i] = 1;
        for(int i=1;i<ratings.length;i++){
            if(ratings[i]>ratings[i-1])
                rst[i] = rst[i-1]+1;
        }

        for(int i=ratings.length-1;i>0;i--){
            if(ratings[i-1]>ratings[i]){
                rst[i-1] = Math.max(rst[i]+1,rst[i-1]);
            }
        }

        int sum=0;
        for(int i=0;i<rst.length;i++){
            sum+=rst[i];
        }
        return sum;
    }
    public static void main(String[] args){
        Candy candy = new Candy();
        int[] num = {0};
        candy.candy(num);
    }
}
